<?php

namespace app\command;

use app\model\UserModel;
use Dsxwk\Framework\WebmanHelper\Console\BaseCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('demo:command', '命令行测试')]
class DemoCommand extends BaseCommand
{
//    protected static string $defaultName        = 'demo:command';
//
//    protected static string $defaultDescription = '命令行测试';

    /**
     * @return void
     */
    protected function configure(): void
    {
        $this->addArgument('test', InputArgument::OPTIONAL, '测试参数')->addOption(
            'name',
            'na',
            InputOption::VALUE_OPTIONAL,
            'test name'
        );
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     *
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $desc = $input->getArgument('test');
        $user = UserModel::query()->first();
        $output->writeln(sprintf('%s option:%s username:%s', $this->getDescription(), $desc, $user?->username));

        return self::SUCCESS;
    }

}
